﻿/*客户定制报表*/
function CustomerReport1Win() {
    var day = new Date();
    var today = day.getFullYear() + '-' + padLeft((day.getMonth() + 1).toString(), "0", 2) + '-' + padLeft(day.getDate().toString(), "0", 2);
    var yyday = addDays(day, -1);
    var yestoday = yyday.getFullYear() + '-' + padLeft((yyday.getMonth() + 1).toString(), "0", 2) + '-' + padLeft(yyday.getDate().toString(), "0", 2);
    var pagesize = 65535;

    var trackNameCombo = getTrackerCheckboxCombo(true);

    var cmbQuickTimer = new Ext.form.ComboBox({
        editable: false,
        forceSelection: true,
        disableKeyFilter: true,
        typeAhead: false,
        mode: 'local',
        triggerAction: 'all',
        width: 50,
        store: new Ext.data.ArrayStore({
            fields: [{ name: 'val', type: 'integer' }, 'text'],
            data: [[0, _Time_Today], [1, _Time_Yesterday], [2, _Time_7Days], [3, _Time_ThisMonth], [4, _Time_30Days]]
        }),
        displayField: 'text',
        width: 100,
        valueField: 'val'
    });
    cmbQuickTimer.setValue(0);

    cmbQuickTimer.addListener('select', function(obj, record, index) {
        var val = record.get('val');

        var day = new Date();
        var tmpbegintstr = today;
        var tmpendstr = today;
        if (val == 0) {
            tmpbegintstr = today;
            tmpendstr = today;
        }
        else if (val == 1) {
            tmpbegintstr = yestoday;
            tmpendstr = yestoday;
        }
        else if (val == 2) {
            var tmpd = addDays(day, -6);
            tmpbegintstr = tmpd.getFullYear() + '-' + padLeft((tmpd.getMonth() + 1).toString(), '0', 2) + '-' + padLeft(tmpd.getDate().toString(), '0', 2);
            tmpendstr = today;
        }
        else if (val == 3) {
            var tmpd = addDays(day, -6);
            tmpbegintstr = tmpd.getFullYear() + '-' + padLeft((tmpd.getMonth() + 1).toString(), '0', 2) + '-01';
            tmpendstr = today;
        }
        else if (val == 4) {
            var tmpd = addDays(day, -30);
            tmpbegintstr = tmpd.getFullYear() + '-' + padLeft((tmpd.getMonth() + 1).toString(), '0', 2) + '-' + padLeft(tmpd.getDate().toString(), '0', 2);
            tmpendstr = today;
        }
        fromDateEditor.setValue(tmpbegintstr);
        toDateEditor.setValue(tmpendstr);
        fromTimeEditor.setValue("00:00");
        toTimeEditor.setValue("23:59");
    });

    var fromDateEditor = new Ext.form.DateField({
        renderer: Ext.util.Format.dateRenderer('Y-m-d'),
        format: 'Y-m-d',
        value: today,
        width: 90
    });


    var fromTimeEditor = new Ext.form.TimeField({
        value: '00:00',
        format: 'H:i',
        width: 60
    });

    var toDateEditor = new Ext.form.DateField({
        renderer: Ext.util.Format.dateRenderer('Y-m-d'),
        format: 'Y-m-d',
        value: today,
        width: 90
    });

    var toTimeEditor = new Ext.form.TimeField({
        value: "23:59",
        format: 'H:i',
        width: 60
    });

    var fields = ["index", "trackername", "sssid", 'startcaraddress', 'startcartime', 'returntime',  'startkilometers', 'returnkilometers',  'kilometers'];
    
    var cstore1 = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy(
        {
            url: 'HandlerCustomerReport1',
            method: "POST",
            timeout: 90000
        }),
        reader: new Ext.data.JsonReader(
        {
            fields: fields,
            root: "data",
            totalProperty: "totalCount"
        })
    });
    
    var tbar = new Ext.Toolbar({
        items: [
            _Alarm_TrackerName + ':',
            trackNameCombo,
            {
                xtype: 'tbseparator', width: 5
            },
            _Alarm_FromTime + ':',
            fromDateEditor,
            {
                xtype: 'tbseparator', width: 5
            },
            fromTimeEditor,
            {
                xtype: 'tbseparator', width: 5
            },
            _Alarm_ToTime + ':',
            toDateEditor,
            {
                xtype: 'tbseparator', width: 5
            },
            toTimeEditor,
            {
                xtype: 'tbseparator', width: 5
            },
            {
            tooltip: { text: _TrackerMain_Search, autoHide: true },
            icon: 'images/search16.gif',
            handler: function() {
                    cstore1.load({
                        params: {
                            fromtime: fromDateEditor.getEl().dom.value + ' ' + fromTimeEditor.getEl().dom.value,
                            totime: toDateEditor.getEl().dom.value + ' ' + toTimeEditor.getEl().dom.value,
                            trackName: trackNameCombo.getRawValue(),
                            start: 0,
                            limit: pagesize
                        }
                    });
                }
            },
            {
                tooltip: { text: _TrackerMain_ExportToExcel, autoHide: true },
                icon: 'images/excel16.gif',
                handler: function() {
                    if (!Ext.fly('creportexcel1')) {
                        var frm = document.createElement('form');
                        frm.id = 'creportexcel1';
                        frm.name = id;
                        frm.style.display = 'none';
                        document.body.appendChild(frm);
                    }
                    Ext.Ajax.request({
                        url: 'HandlerExcel',
                        form: Ext.fly('creportexcel1'),
                        method: 'POST',
                        params: {
                            exceltype: 'creportexcel1',
                            start: 0,
                            limit: 60000,
                            trackName: trackNameCombo.getRawValue(),
                            fromtime: fromDateEditor.getEl().dom.value + ' ' + fromTimeEditor.getEl().dom.value,
                            totime: toDateEditor.getEl().dom.value + ' ' + toTimeEditor.getEl().dom.value
                        },
                        isUpload: true
                    });
                }
            }
        ]
        });

        var columns = [{ header: _TrackerMain_Index, width: 50, sortable: true, menuDisabled: true, dataIndex: 'index' },
                    { header: _TrackerMain_TrackerName, width: 100, sortable: true, menuDisabled: true, dataIndex: 'trackername' },
                    { header: _TrackerMain_StartCarAddress, width: 100, sortable: true, menuDisabled: true, dataIndex: 'startcaraddress' },
                    { header: _TrackerMain_StartCarTime, width: 150, sortable: true, menuDisabled: true, dataIndex: 'startcartime' },
                    { header: _TrackerMain_ReturnTime, width:150, sortable: true, menuDisabled: true, dataIndex: 'returntime' },
                    { header: _TrackerMain_StartKilometers, width: 95, sortable: true, menuDisabled: true, dataIndex: 'startkilometers' },
                    { header: _TrackerMain_ReturnKilometers, width: 95, sortable: true, menuDisabled: true, dataIndex: 'returnkilometers' },
                    { header: _Alarm_Distance, width: 95, sortable: true, menuDisabled: true, dataIndex: 'kilometers' }
                          ];

      var grdCustomerReport1 = new Ext.grid.GridPanel({
            store: cstore1,
            loadMask: true,
            columns: columns,
            width: 1100,
            height: 400,
            title: ""
        });

        grdCustomerReport1.addListener('rowdblclick', function(obj, index) {
            

        });

        var customerreport1win = new Ext.Window({
            title: _TrackerMain_StartCarInfo,
            layout: 'fit',
            height: 470,
            width: 900,
            items: grdCustomerReport1,
            tbar: tbar,
            minimizable: true,
            constrain: true,
            listeners: {
                'minimize': function() {
                    addTaskButtonForWindow(customerreport1win);
                }
            }
        });

        cstore1.on('beforeload', function(store) {
            cstore1.baseParams = {
                start: 'start',
                limit: 'limit',
                trackName: trackNameCombo.getRawValue(),
                fromtime: fromDateEditor.getEl().dom.value + ' ' + fromTimeEditor.getEl().dom.value,
                totime: toDateEditor.getEl().dom.value + ' ' + toTimeEditor.getEl().dom.value
            }
        });

        cstore1.on('load', function(store) {
            
        });
        customerreport1win.show();
        
}